// Package requests 处理请求数据和表单验证
package loginRequest

import (
	"arabApi/app/api/requests"
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type LoginRequest struct {
	User string `json:"user,omitempty" valid:"user"`
	Pwd  string `json:"pwd,omitempty" valid:"pwd"`
}

func CheckLogin(data interface{}, c *gin.Context) string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"user": []string{"required"},
		"pwd":  []string{"required"},
	}
	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"user": []string{
			"required:账号必填",
		},
		"pwd": []string{
			"required:账号必填",
		},
	}

	errs := requests.Validate1(data, rules, messages)
	return requests.GetOneErr(errs)
}
